package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.TransportVisitsLog;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.TransportVisitsLogDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-09-16 18:56:07
 */
public class TransportVisitsLogConverts {

    private static Logger LOG = LoggerFactory.getLogger(TransportVisitsLogConverts.class);

    public static List<TransportVisitsLogDTO> convert(List<TransportVisitsLog> transportVisitsLogList) {
        if (CollectionUtils.isEmpty(transportVisitsLogList)) {
            return Collections.EMPTY_LIST;
        }

        List<TransportVisitsLogDTO> transportVisitsLogListResult = Lists.newArrayList();
        for (TransportVisitsLog transportVisitsLog : transportVisitsLogList) {
            transportVisitsLogListResult.add(convert(transportVisitsLog));
        }
        return transportVisitsLogListResult;
    }

    public static TransportVisitsLogDTO convert(TransportVisitsLog transportVisitsLog) {
        try {
            return BeanUtils.copy(transportVisitsLog, TransportVisitsLogDTO.class);
        } catch (Exception e) {
            LOG.error("TransportVisitsLog到TransportVisitsLogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportVisitsLog到TransportVisitsLogDTO转换失败", e);
        }
    }

    public static TransportVisitsLog convert(TransportVisitsLogDTO transportVisitsLogDTO) {
        try {
            return BeanUtils.copy(transportVisitsLogDTO, TransportVisitsLog.class);
        } catch (Exception e) {
            LOG.error("TransportVisitsLogDTO到TransportVisitsLog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "TransportVisitsLogDTO到TransportVisitsLog转换失败", e);
        }
    }
}